package net.edwardstx.brian.rpn;

import java.io.Serializable;

public interface RPNStackItem<T extends Serializable> extends Cloneable, Serializable{

	public Type<? extends RPNStackItem> getAssociatedType();
	
	public T getValue();
	
	public final class Type<T> implements Comparable<Type> {
		private static int nextHashCode = 1;
		private final int index;
		private final String typeName;
		private final Class<T> clazz;
		public Type(String typeName, Class<T> clazz){
			this.index = ++Type.nextHashCode;
			this.typeName = typeName;
			this.clazz = clazz;
		}
		
		public String getTypeName(){
			return typeName;
		}
		
		public Class<T> getTypeClass(){
			return this.clazz;
		}
		@Override
		public int hashCode() {
			return index;
		}

		@SuppressWarnings("rawtypes")
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Type other = (Type) obj;
			return index == other.index;
		}

		@Override
		public int compareTo(Type o) {
			return this.index - o.index;
		}
		
		
	}
}
